feat: add Anti-Corruption Layer pattern#245
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results 1 files 1 suites 1m 41s ⏱️ Results for commit 8bb3b31. |
There was a problem hiding this comment.
Pull request overview
This PR adds a first-class Anti-Corruption Layer (ACL) slice to PatternKit, including a runtime fluent API (AntiCorruptionLayer<TExternal, TDomain>), a Roslyn incremental generator driven by new ACL attributes, and a full legacy order import example with DI + documentation + catalog coverage.
Changes:
- Introduces
AntiCorruptionLayer<TExternal, TDomain>runtime API with validation + translation result modeling, plus unit tests. - Adds
[GenerateAntiCorruptionLayer]+ translator/rule attributes and an incremental generator with diagnostics + generator tests. - Adds a legacy ERP order import example (fluent + generated +
IServiceCollectionintegration) and updates docs/catalogs accordingly.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/PatternKit.Tests/Application/AntiCorruption/AntiCorruptionLayerTests.cs | Adds runtime ACL behavior tests (accept/reject/cancellation/config validation). |
| test/PatternKit.Generators.Tests/AntiCorruptionLayerGeneratorTests.cs | Validates generated factory output and generator diagnostics. |
| test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs | Extends attribute coverage tests to include new ACL attributes. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates pattern catalog expectations to include ACL. |
| test/PatternKit.Examples.Tests/DependencyInjection/PatternKitExampleDependencyInjectionTests.cs | Ensures the new ACL example is DI-importable alongside others. |
| test/PatternKit.Examples.Tests/AntiCorruptionDemo/LegacyOrderAntiCorruptionDemoTests.cs | Adds end-to-end example tests for fluent + generated + DI flows. |
| src/PatternKit.Generators/AntiCorruption/AntiCorruptionLayerGenerator.cs | Implements the ACL incremental generator and PKACL diagnostics. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Registers new PKACL diagnostic IDs for release tracking. |
| src/PatternKit.Generators.Abstractions/AntiCorruption/AntiCorruptionAttributes.cs | Adds new generator-facing attributes for ACL translation + validation rules. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Adds ACL entry to the pattern coverage catalog. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Adds “Legacy Order Anti-Corruption Layer” example descriptor. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Wires the ACL example into PatternKit’s DI example registry. |
| src/PatternKit.Examples/AntiCorruptionDemo/LegacyOrderAntiCorruptionDemo.cs | Introduces the legacy order ACL demo (fluent + generated + DI). |
| src/PatternKit.Core/Application/AntiCorruption/AntiCorruptionLayer.cs | Adds the runtime ACL implementation and result type. |
| docs/patterns/toc.yml | Adds an Application Architecture section and links to the ACL pattern page. |
| docs/patterns/application/anti-corruption-layer.md | Documents the ACL runtime pattern and production notes. |
| docs/guides/pattern-coverage.md | Updates coverage table to include the ACL pattern + generator. |
| docs/generators/toc.yml | Adds the ACL generator doc page to the generator docs TOC. |
| docs/generators/index.md | Adds ACL generator to the generator index table and examples. |
| docs/generators/anti-corruption-layer.md | Documents generator usage, rules, and diagnostics prefix. |
| docs/examples/toc.yml | Adds the legacy order ACL example to the examples TOC. |
| docs/examples/legacy-order-anti-corruption-layer.md | Documents the legacy order ACL example usage and what it demonstrates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| => AddExternalRule(value => !predicate(value), reason); | ||
|
|
||
| public Builder RequireExternal(Validator<TExternal> predicate, string reason) | ||
| => AddExternalRule(predicate, reason); | ||
|
|
||
| public Builder RejectDomainWhen(Validator<TDomain> predicate, string reason) | ||
| => AddDomainRule(value => !predicate(value), reason); |
| public async ValueTask<AntiCorruptionResult<TDomain>> TranslateAsync( | ||
| TExternal external, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| return await new ValueTask<AntiCorruptionResult<TDomain>>(Translate(external)).ConfigureAwait(false); |
| sb.Append(GetAccessibility(type.DeclaredAccessibility)).Append(' '); | ||
| if (type.IsStatic) | ||
| sb.Append("static "); | ||
| else if (type.IsAbstract && type.TypeKind == TypeKind.Class) | ||
| sb.Append("abstract "); | ||
| else if (type.IsSealed && type.TypeKind == TypeKind.Class) | ||
| sb.Append("sealed "); | ||
| sb.Append("partial ").Append(type.TypeKind == TypeKind.Struct ? "struct" : "class").Append(' ').Append(type.Name).AppendLine(); | ||
| sb.AppendLine("{"); |
| private static void Generate(SourceProductionContext context, INamedTypeSymbol type, TypeDeclarationSyntax node, AttributeData attribute) | ||
| { | ||
| if (!node.Modifiers.Any(static modifier => modifier.Text == "partial")) | ||
| { | ||
| context.ReportDiagnostic(Diagnostic.Create(MustBePartial, node.Identifier.GetLocation(), type.Name)); | ||
| return; | ||
| } | ||
|
|
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #245 +/- ##
==========================================
+ Coverage 91.19% 96.30% +5.10%
==========================================
Files 296 300 +4
Lines 27849 28167 +318
Branches 3876 3921 +45
==========================================
+ Hits 25397 27125 +1728
+ Misses 1096 1042 -54
+ Partials 1356 0 -1356
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code Coverage |
Closes #232
Summary
AntiCorruptionLayer<TExternal, TDomain>with external validation, translation, domain validation, and explicit rejection results[GenerateAntiCorruptionLayer]plus translator/rule attributes and generator diagnosticsLocal validation
dotnet build src\PatternKit.Core\PatternKit.Core.csproj -c Release --no-restore --framework net8.0dotnet build src\PatternKit.Core\PatternKit.Core.csproj -c Release --no-restore --framework net9.0dotnet build src\PatternKit.Core\PatternKit.Core.csproj -c Release --no-restore --framework net10.0dotnet build src\PatternKit.Core\PatternKit.Core.csproj -c Release --no-restore --framework netstandard2.0dotnet build src\PatternKit.Generators\PatternKit.Generators.csproj -c Release --no-restoredotnet build test\PatternKit.Tests\PatternKit.Tests.csproj -c Release --no-restore --no-dependencies --framework net8.0dotnet build test\PatternKit.Generators.Tests\PatternKit.Generators.Tests.csproj -c Release --no-restore --no-dependencies --framework net8.0dotnet test test\PatternKit.Tests\PatternKit.Tests.csproj -c Release --no-build --framework net8.0 --filter FullyQualifiedName~AntiCorruptionLayerTestsdotnet test test\PatternKit.Generators.Tests\PatternKit.Generators.Tests.csproj -c Release --no-build --framework net8.0 --filter FullyQualifiedName~AntiCorruptionLayerGeneratorTestsdotnet test test\PatternKit.Generators.Tests\PatternKit.Generators.Tests.csproj -c Release --no-build --framework net8.0 --filter FullyQualifiedName~AbstractionsAttributeCoverageTestsgit diff --cached --checkNote: local full example/generator test restore/build still hits the known local compiler/analyzer mismatch (
CS9057, generated types absent from unrelated demos). Hosted CI should be authoritative for the generated example surfaces.